#import "DDCouponCell.h"
CGFloat const JTWCOUPONCELLHEIGHT = 80;
@interface DDCouponCell()
@property (nonatomic, strong) CCLabel *titleLBL;
@property (nonatomic, strong) CCLabel *dateLBL;
@property (nonatomic, strong) CCLabel *moneyLBL;
@property (nonatomic, strong) CCLabel *tipsLBL;
@end
@implementation DDCouponCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.cornerRadius = 5.0;
        self.layer.masksToBounds = YES;
    }
    return self;
}
- (CCLabel *)titleLBL
{
    if (!_titleLBL)
    {
        _titleLBL = [[CCLabel alloc] init];
        _titleLBL.font = FONT(UIFontWeightBold, 17);
        _titleLBL.textColor = TEXT_BLACK_COLOR;
        [self addSubview:_titleLBL];
        _titleLBL.c_left.equal(self).with.coffset(GAP);
        _titleLBL.c_bottom.equal(self.c_centerY).with.coffset(-GAP);
    }
    return _titleLBL;
}
- (CCLabel *)moneyLBL
{
    if (!_moneyLBL)
    {
        _moneyLBL = [[CCLabel alloc] init];
        _moneyLBL.font = FONT(UIFontWeightBold, 17);
        _moneyLBL.textColor = RED_COLOR;
        [self addSubview:_moneyLBL];
        _moneyLBL.c_right.equal(self).with.coffset(-GAP);
        _moneyLBL.c_bottom.equal(self.c_centerY).with.coffset(-GAP);
    }
    return _moneyLBL;
}
- (CCLabel *)dateLBL
{
    if (!_dateLBL)
    {
        _dateLBL = [[CCLabel alloc] init];
        _dateLBL.font = FONT(UIFontWeightLight, 14);
        _dateLBL.textColor = TEXT_GRAY_COLOR;
        [self addSubview:_dateLBL];
        _dateLBL.c_left.equal(self).with.coffset(GAP);
        _dateLBL.c_top.equal(self.c_centerY).with.coffset(GAP);
    }
    return _dateLBL;
}
- (CCLabel *)tipsLBL
{
    if (!_tipsLBL)
    {
        _tipsLBL = [[CCLabel alloc] init];
        _tipsLBL.font = FONT(UIFontWeightLight, 14);
        _tipsLBL.textColor = TEXT_GRAY_COLOR;
        [self addSubview:_tipsLBL];
        _tipsLBL.c_right.equal(self).with.coffset(-GAP);
        _tipsLBL.c_top.equal(self.c_centerY).with.coffset(GAP);
    }
    return _tipsLBL;
}
DDCouponCellManager couponCellManager()
{
    DDCouponCellManager manager =
    {
        _getPara,
        _setPara,
        _destroy
    };
    return manager;
};
static DDCouponCellPara _para;
static DDCouponCellPara _getPara()
{
    return _para;
};
static void _setPara(DDCouponCell *cell, DDCouponCellPara para)
{
    _para = para;
    if (cell)
    {
        cell.titleLBL.text = _para.title;
        cell.dateLBL.text = [NSString stringWithFormat:@"有效期至: %@",_para.date];
        cell.moneyLBL.text = [NSString stringWithFormat:@"¥ %@",_para.money];
        cell.tipsLBL.text = _para.tips;
    }
}
static DDCouponCellPara _destroy(DDCouponCellPara para)
{
    para.title = nil;
    para.date = nil;
    para.money = nil;
    para.tips = nil;
    _para = para;
    return para;
}
- (void)setSelected:(BOOL)selected
{
    [super setSelected:selected];
    self.backgroundColor = (selected)?helpermanger().getPara().color:[UIColor whiteColor];
    self.moneyLBL.textColor = (selected)?[UIColor whiteColor]:RED_COLOR;
    self.dateLBL.textColor = (selected)?[UIColor whiteColor]:TEXT_GRAY_COLOR;
    self.tipsLBL.textColor = (selected)?[UIColor whiteColor]:TEXT_GRAY_COLOR;
}

@end
